package com.rc.pojo.dto.activity;

import com.rc.pojo.po.Comment;
import org.springframework.util.CollectionUtils;

import java.util.Comparator;
import java.util.List;

public interface BaseLastThreeVO {

    void setLastThreeAvatars(List<String> avatars);
    void setLastComment(String content);

    static  void set(BaseLastThreeVO  vo, List<Comment> comments){
        if (!CollectionUtils.isEmpty(comments)){
            //最后三个评论人的头像
            List<String> lastThreeAvatars = comments.stream()
                    .map(Comment::getAvatar)
                    .toList();

            vo.setLastThreeAvatars(lastThreeAvatars);

            //最后一条评论
            String content = comments.stream()
                    .max(Comparator.comparing(Comment::getCreateTime))
                    .orElse(new Comment())
                    .getContent();

           vo.setLastComment(content);
        }
    }
}
